﻿using System.Windows;
using K9Tools.WordTools;

namespace K9Tools.Plugins.WordTools.ViewModels;

public class MainViewModel : BindableBase
{
    private string _imageSourcePath;
    private string _outputFile;
    private int _rows = 2;
    private int _columns = 3;
    private float _scale = 0.95F;

    public MainViewModel()
    {
        ConvertCommand = new(HandleConvert);
    }

    public string ImageSourcePath
    {
        get => _imageSourcePath;
        set => SetProperty(ref _imageSourcePath, value);
    }

    public string OutputFile { get => _outputFile; set => SetProperty(ref _outputFile, value); }

    public int Rows { get => _rows; set => SetProperty(ref _rows, value); }

    public int Columns { get => _columns; set => SetProperty(ref _columns, value); }

    public float Scale { get => _scale; set => SetProperty(ref _scale, value); }

    public DelegateCommand ConvertCommand { get; }

    private void HandleConvert()
    {
        if (string.IsNullOrWhiteSpace(ImageSourcePath)|| string.IsNullOrWhiteSpace(OutputFile))
        {
            return;
        }
        try
        {
            WordImageCombiner.CreateImageDocument(OutputFile, ImageSourcePath, Scale,Columns, Rows);
            MessageBox.Show("转换完成！", "成功", MessageBoxButton.OK, MessageBoxImage.Information);
        }
        catch (Exception ex)
        {
            MessageBox.Show("转换过程中发生错误："+ ex.Message,
                "错误", MessageBoxButton.OK, MessageBoxImage.Error);
        }

    }
}
